package com.app.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.app.conf.CustomLocalDateTimeDeserializer;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 承租人关系记录表
 * </p>
 *
 * @author yoominic
 * @since 2025-03-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("tb_tenant_relationship")
public class TenantRelationship implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 自增主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 唯一标识
     */
    private String uniqueId;

    /**
     * 租赁证编号
     */
    private String leaseCertificateNumber;


    private String faceUrl;

    /**
     * 租户序列号  第几承租人
     */
    private Integer tenantSerialNumber;

    /**
     * 承租人姓名
     */
    private String tenantName;

    /**
     * 承租人工作单位
     */
    private String tenantCompany;

    /**
     * 承租人身份证
     */
    private String tenantIdCard;

    @TableField(exist = false)
    private String tenantIdCardFour;

    /**
     * 第一承租人电话
     */
    private String tenantPhone;

    /**
     * 建立租赁关系时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime leaseRelationshipTime;

    /**
     * 家庭成员json格式 name为姓名，relationships为关系，workUnit工作单位
     */
    private String familyMembersJson;

    /**
     * 缴纳保证金
     */
    private BigDecimal depositPaid;

    /**
     * 缴纳时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime paymentTime;

    /**
     * 归还保证金
     */
    private BigDecimal depositReturned;

    /**
     * 归还时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime returnTime;

    /**
     * 新保证金
     */
    private BigDecimal newDeposit;


    /**
     * 新保证金缴纳时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime newDepositPaymentTime;

    /**
     * 新归还保证金
     */
    private BigDecimal newDepositReturned;

    /**
     * 新归还保证金时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime newDepositReturnTime;

    /**
     * 超面积计租
     */
    private BigDecimal excessAreaRent;

    /**
     * 政策减免
     */
    private BigDecimal policyReduction;

    /**
     * 合计月租
     */
    private BigDecimal totalMonthlyRent;

    /**
     * 其它变量
     */
    private BigDecimal otherVariable;

    /**
     * 地下室变量
     */
    private BigDecimal basementVariable;

    /**
     * 状态 0无效 1租赁中 2已退租 3已变更
     */
    private Integer status;

    /**
     * 居住状态
     */
    private LocalDateTime liveStatus;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime createTime;

    private Integer createUser;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime updateTime;

    private Integer updateUser;

    private String wechatBoundPhone;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime boundTime;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
    private LocalDateTime faceAuthenticationTime;

    @TableField(exist = false)
    private String houseType;

    @TableField(exist = false)
    private String areaName;

    @TableField(exist = false)
    private String streetName;

    @TableField(exist = false)
    private String buildingNumber;

    @TableField(exist = false)
    private String unitNumber;

    @TableField(exist = false)
    private String floorLevel;

    @TableField(exist = false)
    private String roomNumber;

    @TableField(exist = false)
    private String mphValue;

    @TableField(exist = false)
    private String remarks;

    @TableField(exist = false)
    private Boolean isArrearage;

    @TableField(exist = false)
    private String wechatPhoneNumber;

    @TableField(exist = false)
    private JSONArray familyMembers;

    @TableField(exist = false)
    private Integer familyMembersCount;

    @TableField(exist = false)
    private List<TenantRelationship> tenantRelationships;

    @TableField(exist = false)
    private Integer fwId;

    @TableField(exist = false)
    private String leaseCertificateNumberNew;

    @TableField(exist = false)
    private Integer type;

    // 获取 houseInfo 的 JSON 字符串
    @Getter
    @TableField(exist = false)
    private String houseInfo;

    @TableField(exist = false)
    private List<Map<String, Object>> houseInfoList;  // 存储解析后的集合
}
